﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class cms_default : System.Web.UI.Page
{
    AbbonementManager abom;

    protected void Page_Load(object sender, EventArgs e)
    {

        abom = new AbbonementManager((debioscoopEntities)Session["db"]);
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        AbonnementDetailsView.Visible = true;
        AbonnementDetailsView.ChangeMode(DetailsViewMode.Insert);
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        AbonnementDetailsView.ChangeMode(DetailsViewMode.ReadOnly);
        AbonnementGridView.SelectedIndex = -1;
    }

    protected void AbonnementDetailsView_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
    {
        AbonnementGridView.DataBind();
    }

    protected void AbonnementDetailsView_ItemUpdated(object sender, DetailsViewUpdatedEventArgs e)
    {
        AbonnementGridView.DataBind();
    }

    protected void AbonnementDetailsView_ItemDeleted(object sender, DetailsViewDeletedEventArgs e)
    {
        AbonnementGridView.DataBind();
    }

    //protected void AbonnementDetailsView_ItemInserting(object sender, DetailsViewInsertEventArgs e)
    //{
    //    try
    //    {

    //        DropDownList FilmsList = (DropDownList)PlanningDetailsOverview.FindControl("Film_drop");
    //        DropDownList BiosList = (DropDownList)PlanningDetailsOverview.FindControl("Bioscoop_drop");
    //        DropDownList ZaalList = (DropDownList)PlanningDetailsOverview.FindControl("Zaal_drop");
    //        CheckBox Drie_D = (CheckBox)PlanningDetailsOverview.FindControl("Drie_D");
    //        TextBox time = (TextBox)PlanningDetailsOverview.FindControl("txtTijd");
    //        TextBox date = (TextBox)PlanningDetailsOverview.FindControl("txtDatum");

    //        planning insertPlanning = new planning();
    //        insertPlanning.zaalbioscoopbioscoop_id = int.Parse(BiosList.SelectedValue);
    //        insertPlanning.tijd = TimeSpan.Parse(time.Text);
    //        insertPlanning.datum = DateTime.ParseExact(date.Text, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);
    //        insertPlanning.dried = Drie_D.Checked;



    //        not sure if I should use this. I didn't need it elsewhere
    //        insertPlanning.zaalzaalnummer = int.Parse(ZaalList.SelectedValue);
    //        insertPlanning.filmfilm_id = int.Parse(FilmsList.SelectedValue);


    //        pm.addPlanning(insertPlanning);
    //    }
    //    catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
    //    {
    //        foreach (var validationErrors in dbEx.EntityValidationErrors)
    //        {
    //            foreach (var validationError in validationErrors.ValidationErrors)
    //            {
    //                System.Diagnostics.Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
    //            }
    //        }
    //    }
    //}
    //protected void AbonnementDetailsView_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
    //{
    //    DropDownList FilmsList = (DropDownList)PlanningDetailsOverview.FindControl("Film_drop");
    //    DropDownList BiosList = (DropDownList)PlanningDetailsOverview.FindControl("Bioscoop_drop");
    //    DropDownList ZaalList = (DropDownList)PlanningDetailsOverview.FindControl("Zaal_drop");
    //    CheckBox Drie_D = (CheckBox)PlanningDetailsOverview.FindControl("Drie_D");
    //    TextBox time = (TextBox)PlanningDetailsOverview.FindControl("txtTijd");
    //    TextBox date = (TextBox)PlanningDetailsOverview.FindControl("txtDatum");

    //    PlanningDetails.InsertCommand = "UPDATE planning SET tijd=" + time.Text + ", datum=" + date.Text + ", dried=" + Drie_D + ", zaalbioscoopbioscoop_id=" + BiosList.SelectedValue + ", zaalzaalnummer=" + ZaalList.SelectedValue + ", filmfilm_id=" + FilmsList.SelectedValue + " WHERE planning_id =" + PlanningGridView.SelectedValue;
    //    PlanningDetails.Insert();


    //    planning updatePlanning = pm.getPlanning(int.Parse(PlanningGridView.SelectedValue.ToString()));
    //    updatePlanning.zaalbioscoopbioscoop_id = int.Parse(BiosList.SelectedValue);
    //    updatePlanning.zaalzaalnummer = int.Parse(ZaalList.SelectedValue);
    //    updatePlanning.filmfilm_id = int.Parse(FilmsList.SelectedValue);
    //    updatePlanning.tijd = TimeSpan.Parse(time.Text);
    //    updatePlanning.datum = DateTime.Parse(date.Text);
    //    updatePlanning.dried = Drie_D.Checked;
    //    pm.executeQuery();


    //}

    //protected void AbonnementDetailsView_ItemInserting(object sender, DetailsViewInsertEventArgs e)
    //{
    //    TextBox abo = (TextBox)AbonnementDetailsView.FindControl("TextBox1");
    //    DropDownList periode = (DropDownList)AbonnementDetailsView.FindControl("Abomdrop");

    //    abo.Text = periode.SelectedValue;

    //}
    //protected void AbonnementDetailsView_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
    //{
    //    TextBox abo = (TextBox)AbonnementDetailsView.FindControl("TextBox1");
    //    DropDownList periode = (DropDownList)AbonnementDetailsView.FindControl("Abomdrop");

    //    abo.Text = periode.SelectedValue;
    //}
    protected void AbomDrop_SelectedIndexChanged(object sender, EventArgs e)
    {
        TextBox abo = (TextBox)AbonnementDetailsView.FindControl("TextBox1");
        DropDownList periode = (DropDownList)AbonnementDetailsView.FindControl("Abomdrop");

        abo.Text = periode.SelectedValue;
    }

    protected void Abonnement_SelectedIndexChanged(object sender, EventArgs e)
    {
        AbonnementDetailsView.ChangeMode(DetailsViewMode.ReadOnly);
    }

}